@extends('home.common.home_layout')
@section('content')
	<link rel="stylesheet" href="/lei/home/shenqing.css">
	<div style="width:1200px;height:100%;">
		<div style="width:1050px;height:45px;background:#ccc">
			<h1>e行商户中心</h2>
		</div>
		<div style="width:1050px;padding-left:50px;">
			<form class="navbar-form navbar-left" role="search" action="/home/aptitude" id="art_form" method="post"  enctype="multipart/form-data">
				{{ csrf_field() }}
				  <div class="form-group" id="ap_bus">
				    	<b class="icon">*</b></label><span>门店名称：　　　　</span><input type="text" id="ap_business" name="ap_business" class="form-control" style="width:300px"><span></span>
				  </div><br>
				  <div class="form-group" id="b_ph">
				    	<b class="icon">*</b></label><span>店铺电话：　　　　</span><input type="text" id="b_phone" name="b_phone" class="form-control"><span></span>
				  </div><br>
				  <div class="form-group" id="ap_n">
				    	<b class="icon">*</b></label><span>联系人姓名：　　　</span><input type="text" id="ap_name" name="ap_name" class="form-control" style="width:150px;"><span></span>
				  </div><br>
				  <div class="form-group" id="ap_a">
				    	<b class="icon">*</b></label><span>联系人年龄：　　　</span><input type="text" id="ap_age" name="ap_age" class="form-control" style="width:100px;"><span></span>
				  </div><br>
				  <div class="form-group" id="ap_num">
				    	<b class="icon">*</b></label><span>联系人身份证号码：</span><input type="text" id="ap_number" name="ap_number" class="form-control" style="width:400px;"><span></span>
				  </div><br>
				  <div class="form-group" id="gt_ty">
				    	<b class="icon">*</b></label><span>门店分类：　　　　</span><input type="text" id="gt_type" name="gt_type" class="form-control" placeholder="例如:川菜...最多俩个"><span></span>
				  </div><br>
				  <div class="form-group" id="time">
				    	<b class="icon">*</b></label><span>营业时间：　　　　</span><input type="time" id="startime" name="startime" class="form-control"> ~~ <input type="time" id="endtime" name="endtime" class="form-control"><span></span>
				  </div><br>
				  <div class="form-group" id="b_add">
				    	<b class="icon">*</b></label><span>详细地址：　　　　</span><input type="text" id="b_address" name="b_address" class="form-control"><span></span>
				  </div><br>
				  <input type="hidden" name="ap_status" value="0">	
				  <div class="form-group">
				    	<div style="float:left;"><b class="icon">*</b></label><span>营业执照图片：　　</span></div>
				    	<div style="border:1px solid #ccc;width:700px;height:122px;float:left;">
				    		<div style="width:200px;float:left;">
				    			示例:<img src="/lei/images/zhizhao.png" style="height:120px;" alt="">
				    		</div>
				    		<div style="float:left;margin-top:50px;">
				    			<input type="hidden" name="license" id="license" value="">
				    			<input id="file_license" name="file_license" type="file" multiple="true">
				    		</div>
							<div>
								<img id="img1" src="" style="height:120px;" alt="">
							</div>	
				    	</div>
				  </div><br>

				  <div class="form-group">
				  		<div style="float:left;"><b class="icon">*</b></label><span>卫生许可证图片：　</span></div>
				    	<div style="border:1px solid #ccc;width:700px;height:122px;float:left;">
				    		<div style="width:200px;float:left;">
				    			示例:<img src="/lei/images/weisheng.png" style="height:120px;" alt="">
				    		</div>
				    		<div style="float:left;margin-top:50px;">
				    			<input type="hidden" name="permit" id="permit" value="">
				    			<input id="file_permit" name="file_permit" type="file" multiple="true">
				    		</div>
				    		<div>
								<img id="img2" src="" style="height:120px;" alt="">
							</div>
				    	</div>
				  </div><br><br>
				  <div style="width:880px;height:50px;background:#ccc;float:left;">
					    <input type="submit" class="btn-info" value="提交申请" style="width:100px;height:50px;margin-left:300px;">
					    <input type="reset" class="btn-info" value="重新填写" style="width:100px;height:50px;margin-left:50px;">
				  </div>
			</form>
		</div>
	</div>	 	
	
	<script>
		$('#ap_business').blur(function(){
			var bus = $('#ap_business').val();
			$.get('/home/aptitude/create',{'ap_business':bus,'_token':'{{csrf_token()}}'},function(msg){
				if(msg==0){
					$('#ap_bus span').eq(1).html('<span style="font-size:10px;color:red;">✘店铺名已存在，请重新填写</span>');
				}else if(msg==1){
					$('#ap_bus span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
				}else if(msg==2){
					$('#ap_bus span').eq(1).html('<span style="font-size:10px;color:red;">✘店铺名不能为空</span>');
				}
			});
		});
		$('#b_phone').blur(function(){
			var phone = $('#b_phone').val();
			if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){ 
		        $('#b_ph span').eq(1).html('<span style="font-size:10px;color:red;">✘手机号码有误，请重新填写</span>');
		    }else{
		    	$('#b_ph span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
		    } 
		});
		$('#ap_name').blur(function(){
			if(!$('#ap_name').val()){
				$('#ap_n span').eq(1).html('<span style="font-size:10px;color:red;">✘姓名不能为空</span>');
			}else{
				$('#ap_n span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		$('#ap_age').blur(function(){
			var age = $('#ap_age').val();
			if(!(/^(2|3|4|5|6|7)\d$/.test(age))){
				$('#ap_a span').eq(1).html('<span style="font-size:10px;color:red;">✘年龄不能为空</span>');
			}else{
				$('#ap_a span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		$('#ap_number').blur(function(){
			var num = $('#ap_number').val();
			if(!(/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(num))){
				$('#ap_num span').eq(1).html('<span style="font-size:10px;color:red;">✘身份证不正确</span>');
			}else{
				$('#ap_num span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		$('#gt_type').blur(function(){
			if(!$('#gt_type').val()){
				$('#gt_ty span').eq(1).html('<span style="font-size:10px;color:red;">✘分类不能为空</span>');
			}else{
				$('#gt_ty span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		$('#startime').blur(function(){
			if(!$('#startime').val()){
				$('#time span').eq(1).html('<span style="font-size:10px;color:red;">✘时间不能为空</span>');
			}else{
				$('#time span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		$('#endtime').blur(function(){
			if(!$('#endtime').val()){
				$('#time span').eq(1).html('<span style="font-size:10px;color:red;">✘时间不能为空</span>');
			}else{
				$('#time span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		$('#b_address').blur(function(){
			var add = $('#b_address').val();
			if(!$('#b_address').val()){
				$('#b_add span').eq(1).html('<span style="font-size:10px;color:red;">✘地址不能为空</span>');
			}else{
				$('#b_add span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		$(function () {
            $("#file_license").change(function () {
                uploadImage();
            });
        });

        //上传图片
        function uploadImage() {
		//判断是否有选择上传文件
            var imgPath = $("#file_license").val();
            if (imgPath == "") {
                alert("请选择上传图片！");
                return;
            }
            //判断上传文件的后缀名
            var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1).toLowerCase();
            if (strExtension != 'jpg' && strExtension != 'gif'
                && strExtension != 'png' && strExtension != 'bmp') {
                alert("请选择图片文件");
                return;
            }
            var formData = new FormData();
            formData.append("file_license", $('#file_license')[0].files[0]);
            formData.append("_token", '{{csrf_token()}}');
            $.ajax({
                type: "post",
                url: "/upload/license",
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
                    $('#img1').attr('src','/'+data);
                    $('#license').val(data);

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("上传失败，请检查网络后重试");
                }
            });
        }
        $(function () {
            $("#file_permit").change(function () {
                uploadImages();
            });
        });

        //上传图片
        function uploadImages() {
		//判断是否有选择上传文件
            var imgPath = $("#file_permit").val();
            if (imgPath == "") {
                alert("请选择上传图片！");
                return;
            }
            //判断上传文件的后缀名
            var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1).toLowerCase();
            if (strExtension != 'jpg' && strExtension != 'gif'
                && strExtension != 'png' && strExtension != 'bmp') {
                alert("请选择图片文件");
                return;
            }
            var formData = new FormData();
            formData.append("file_permit", $('#file_permit')[0].files[0]);
            formData.append("_token", '{{csrf_token()}}');
            $.ajax({
                type: "post",
                url: "/upload/permit",
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
                    $('#img2').attr('src','/'+data);
                    $('#permit').val(data);

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("上传失败，请检查网络后重试");
                }
            });
        }
	</script>
@endsection